<html>
<head><meta charset="utf-8"><title>Target-specific examples, binaries, etc · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Target-specific.20examples.2C.20binaries.2C.20etc.html">Target-specific examples, binaries, etc</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223296260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Target-specific%20examples%2C%20binaries%2C%20etc/near/223296260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Target-specific.20examples.2C.20binaries.2C.20etc.html#223296260">(Jan 19 2021 at 21:18)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> mentioned a need to have target-specific examples, such as an example that only builds on Windows. I think that makes sense, and Cargo could support that.</p>
<p>I can think of a few ways to handle that. One way would be to add <code>required-cfg</code>, analogous to <code>required-features</code>:</p>
<div class="codehilite" data-code-language="TOML"><pre><span></span><code><span class="k">[[example]]</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"some-example"</span>
<span class="n">required-cfg</span> <span class="o">=</span> <span class="k">["cfg(windows)"]</span>
</code></pre></div>
<p>Another way would be to add <code>[[target.'cfg(...)'.example]]</code> support:</p>
<div class="codehilite" data-code-language="TOML"><pre><span></span><code><span class="k">[[target.'cfg(windows)'.example]]</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"some-example"</span>
</code></pre></div>



<a name="223296488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Target-specific%20examples%2C%20binaries%2C%20etc/near/223296488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Target-specific.20examples.2C.20binaries.2C.20etc.html#223296488">(Jan 19 2021 at 21:20)</a>:</h4>
<p>A third approach (related to the second) would be to add a more generalized <code>cfg</code> mechanism that can affect <em>any</em> field in the manifest: a cfg-gated section that gets merged into the rest of the manifest (if its cfg is satisfied) before Cargo does anything else with the manifest.</p>



<a name="223296723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Target-specific%20examples%2C%20binaries%2C%20etc/near/223296723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Target-specific.20examples.2C.20binaries.2C.20etc.html#223296723">(Jan 19 2021 at 21:22)</a>:</h4>
<p>One thing that would be key here is that any automatic general "build all the examples" that doesn't specifically name a particular cfg'd example should just quietly overlook said example.</p>
<p>in other words, <code>cargo test</code> and <code>cargo build --examples</code> when there's a cfg(windows) example would still succeed on a unix machine.  (possibly with a warning or other log message about about an example being skipped over)</p>



<a name="223296796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Target-specific%20examples%2C%20binaries%2C%20etc/near/223296796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Target-specific.20examples.2C.20binaries.2C.20etc.html#223296796">(Jan 19 2021 at 21:22)</a>:</h4>
<p>I don't even think it should be a warning. A verbose informational message at most, I think.</p>



<a name="223296975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Target-specific%20examples%2C%20binaries%2C%20etc/near/223296975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Target-specific.20examples.2C.20binaries.2C.20etc.html#223296975">(Jan 19 2021 at 21:24)</a>:</h4>
<p>yeah some sort of "please note: some examples were skipped during this build"</p>



<a name="223297049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Target-specific%20examples%2C%20binaries%2C%20etc/near/223297049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Target-specific.20examples.2C.20binaries.2C.20etc.html#223297049">(Jan 19 2021 at 21:24)</a>:</h4>
<p>and honestly this should probably all apply to binaries as well.</p>
<p>tests don't need a special treatment because a blank test module isn't an error</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>